<template>
    <div class="target-check-list level-list">
        <el-tabs v-model="activeName">
            <el-tab-pane label="基础信息" name="first">
                <levelForm :disabled="true" :levelType="$route.params.type" :joinOrgHidden="true" :formInfo="formInfo"></levelForm>
            </el-tab-pane>
            <el-tab-pane label="质控点信息" name="second">
                <!-- 搜索 -->
                <listSearch @search="search"></listSearch>

                <!-- 表格 -->
                <myTable
                        :column="column"
                        :tableData="tableData"
                        @changePage="changePage">
                    <el-table-column label="操作" width="150px">
                        <template slot-scope="scope">
                            <el-button type="text" @click="handle('detail', scope.row)">详情</el-button>
                        </template>
                    </el-table-column>
                </myTable>
                <!--<list-->
                        <!--:levelType="$route.params.type"-->
                        <!--:editAble="true"-->
                        <!--:isStart="false"-->
                        <!--:showFiled="['standardValue','targetValue','expectedValue']"-->
                        <!--:total="total"-->
                        <!--:tableData="tableData"-->
                        <!--@changePage="changePage"></list>-->
            </el-tab-pane>
        </el-tabs>
        <div class="back-btn">
            <back-button></back-button>
        </div>

        <!-- 添加质控点 -->
        <addPoint
                v-if="addParams.visible"
                :addParams="addParams"></addPoint>
    </div>
</template>

<script>
    import listSearch from '@/components/search/listSearch'
    import list from '@/components/cardToList/list'
    import myTable from '@/components/table/index.vue'
    import { getMyPointList, getMyTargetById } from '@/api/target';
    import { filterParams } from '@/config/utils';
    import levelForm from '@/views/targetSystem/targetManage/module/levelFrom'
    import addPoint from '@/views/targetSystem/targetManage/module/addPoint'

    export default {
        name: 'queryList',
        components: {
            listSearch,
            list,
            levelForm,
            myTable,
            addPoint
        },
        data () {
            return {
                activeName: 'first',
                searchFrom: {
                    targetStandardId: '',
                    indexOne: '',
                    indexTwo: '',
                    indexThree: '',
                    name: '',
                    pageSize: 10,
                    pageIndex: 1
                },
                column: [
                    {
                        prop: 'indexOne',
                        label: '一级指标'
                    },
                    {
                        prop: 'indexTwo',
                        label: '二级指标'
                    },
                    {
                        prop: 'indexThree',
                        label: '三级指标'
                    },
                    {
                        prop: 'name',
                        label: '质控点'
                    },
                    {
                        prop: 'intension',
                        label: '质控点内涵'
                    },
                    {
                        prop: 'diagnosisStandard',
                        label: '诊断标准'
                    },
                    {
                        prop: 'belongPartName',
                        label: '责任部门'
                    },
                    {
                        prop: 'valueType',
                        label: '值类型'
                    },
                    {
                        prop: 'expectedValue',
                        label: '预期值'
                    },
                    {
                        prop: 'isWarning',
                        label: '是否预警',
                        asyncData: this.$config.yesOrNo
                    },
                    {
                        prop: 'isOptional',
                        label: '是否可选',
                        asyncData: this.$config.isOptional
                    }
                ],
                tableData: [],
                formInfo: null,
                addParams: {
                    visible: false,
                    title: '添加质控点',
                    type: '',
                    id: '',
                    targetStandardId: ''
                }
            }
        },
        created () {
            this.searchFrom.targetStandardId = this.$route.query.id;
            this.getList();
            this.getQueryTargetById()
        },
        methods: {
            // 搜索
            search (searchFrom) {
                this.searchFrom.pageIndex = 1;
                this.searchFrom.indexOne = searchFrom.indexOne;
                this.searchFrom.indexTwo = searchFrom.indexTwo;
                this.searchFrom.indexThree = searchFrom.indexThree;
                this.searchFrom.name = searchFrom.name;
                this.searchFrom.belongPart = searchFrom.belongPart;
                this.getList();
            },
            getList () {
                const params = filterParams(this.searchFrom);
                getMyPointList(params).then(res => {
                    this.tableData = res.dataList || [];
                    this.total = res.total || 0;
                }).catch(() => {})
            },
            // 查询我的目标标准详情
            getQueryTargetById () {
                getMyTargetById(this.searchFrom.targetStandardId).then(res => {
                    this.formInfo = res || {}
                }).catch(() => {
                })
            },
            // 切换分页
            changePage (searchForm) {
                this.searchFrom.pageIndex = searchForm.pageIndex;
                this.searchFrom.pageSize = searchForm.pageSize;
                this.getList()
            },
            handle (type, data) {
                this.addParams = {
                    visible: true,
                    title: '查看质控点',
                    type: type,
                    id: data.id,
                    data: data,
                    targetStandardId: this.searchFrom.targetStandardId
                };
            }
        },
        watch: {
            $route: {
                handler (val) {
                    // 如果index为2,默认打开second的tab页，默认显示质控点信息
                    if (val.query.index === 2) {
                        this.activeName = 'second'
                    }
                },
                deep: true,
                immediate: true
            }
        }
    }
</script>

<style scoped>

</style>
